﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HKEA.CMS.Core.BLL;
using HKEA.CMS.Core.Models;
using HKEA.CMS.Core.Utility;
using System.Transactions;
using System.Collections;
using System.Data;
using System.Text;
using HKEA.CMS.Core.BLL.Mtbl;
using HKEA.CMS.Core.BLL.Tbl;
namespace WebApplication
{
    public partial class ContactPerson : BasePage
    {
        #region 局部标量
        tblCustomer customerENT = new tblCustomer();
        tblCustomerBLL customerBLL = new tblCustomerBLL();
        tblContactPersonBLL cpBLL = new tblContactPersonBLL();
        tblCust_ContactPersonBLL cust_cpBLL = new tblCust_ContactPersonBLL();
        tblAddressBLL addressBLL = new tblAddressBLL();
        tblCPerson_JobNatureBLL cp_jobnatureBLL = new tblCPerson_JobNatureBLL();
        tblCPerson_AttributeBLL cp_attributeBLL = new tblCPerson_AttributeBLL();
        mtblAreaBLL areaBLL = new mtblAreaBLL();
        tblContactInfoBLL infoBLL = new tblContactInfoBLL();
        mtblArea areaENT = new mtblArea();
        tblCPerson_JobNature cp_jobENT = new tblCPerson_JobNature();
        tblCPerson_Attribute cp_attributeENT = new tblCPerson_Attribute();
        tblContactPerson cpENT = new tblContactPerson();
        tblCust_ContactPerson cust_cpENT = new tblCust_ContactPerson();
        tblAddress addressENT = new tblAddress();
        tblContactInfo infoENT = new tblContactInfo();

        tblMediaRoom_Related relatedENT = new tblMediaRoom_Related();
        tblMediaRoomRelatedBLL relatedBLL = new tblMediaRoomRelatedBLL();

        protected int customeruid = 0;
        protected int cpuid = 0;
        bool isToCP = false;
        #endregion
        int telNum = 5;
        int faxNum = 5;
        int emailNum = 5;
        int webNum = 2;
        int addressUID = 0;
        int infoUID = 0;
        protected string type = "";
        List<ContactPersonListDetail> cpList = new List<ContactPersonListDetail>();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.QueryString[Constant.UrlParamName.CustomerUID] != null)
                {
                    if (int.TryParse(Request.QueryString[Constant.UrlParamName.CustomerUID], out customeruid))
                    {
                        int.TryParse(Request.QueryString[Constant.UrlParamName.ContactPersonUID], out cpuid);
                        InitPage();
                        BindStaticInfo();
                    }
                    else
                    {
                        SetNoOption();
                        lblMeg.Text = ResourceManage.GetResourceString("msg200001");
                    }
                }
                else
                {
                    SetNoOption();
                    lblMeg.Text = ResourceManage.GetResourceString("msg200002");
                }
            }
        }

        #region 按钮事件
        protected void btnRefreshImgList_Click(object sender, EventArgs e)
        {
            int.TryParse(Request.QueryString[Constant.UrlParamName.CustomerUID], out customeruid);
            BindPersonImg();
        }
        protected void lkbtnSave_Click(object sender, EventArgs e)
        {
            if (Context.Request.QueryString[Constant.UrlParamName.CustomerUID] != null)
            {
                int.TryParse(Request.QueryString[Constant.UrlParamName.CustomerUID], out customeruid);
                int.TryParse(Request.QueryString[Constant.UrlParamName.ContactPersonUID], out cpuid);
                if (customeruid > 0 && cpuid > 0)
                {
                    cust_cpENT.ContactPersonUID = cpuid;
                    cust_cpENT.CustomerUID = customeruid;
                    cust_cpENT.Deleted = 0;
                    var temp = cust_cpBLL.GetEntity(cust_cpENT);
                    if (temp != null)
                    {
                        UpdateCP();
                        WriteToLog();
                    }
                    else
                    {
                        AddCP();
                        WriteToLog();
                    }
                }
                else if (customeruid > 0)
                {
                    AddCP();
                    WriteToLog();
                }
                BindCPList();
                BindRelatedCPList();
                BingImgRelated(true);
            }
            else
            {
                lblMeg.Text = ResourceManage.GetResourceString("msg200002");
            }
        }
        //AJAX删除Commitee重新绑定数据
        protected void btnRefreshCommitee_Click(object sender, EventArgs e)
        {
            int.TryParse(Request.QueryString[Constant.UrlParamName.CustomerUID], out customeruid);
            int.TryParse(Request.QueryString[Constant.UrlParamName.ContactPersonUID], out cpuid);

            cust_cpENT.CustomerUID = customeruid;
            cust_cpENT.Deleted = 0;
            if (cpuid > 0)
            {
                cust_cpENT.ContactPersonUID = cpuid;
                var temp = cust_cpBLL.GetEntity(cust_cpENT);
                if (temp != null)
                {
                    isToCP = true;
                    BindCommitteeMember(isToCP);
                }
            }
            BindCPList();
        }

        protected void btnRefreshCPList_Click(object sender, EventArgs e)
        {
            int.TryParse(Request.QueryString[Constant.UrlParamName.CustomerUID], out customeruid);
            BindCPList();
            BindRelatedCPList();
        }

        #endregion

        #region  修改按钮
        protected void UpdateCP()
        {
            cust_cpENT.ContactPersonUID = cpuid;
            cust_cpENT.CustomerUID = customeruid;
            cust_cpENT.Deleted = 0;
            cust_cpENT = cust_cpBLL.GetEntity(cust_cpENT);
            if (cust_cpENT != null)
            {
                cpENT.ContactPersonUID = cpuid;
                cpENT = cpBLL.GetEntity(cpENT);
                cpENT = GetCPValue(cpENT);
                if (cpENT.AddressUID != null)
                {
                    addressENT.AddressUID = (int)cpENT.AddressUID;
                    addressENT = addressBLL.GetEntity(addressENT);
                }
                if (cpENT.ContactInfoUID != null)
                {
                    infoENT.ContactInfoUID = (int)cpENT.ContactInfoUID;
                    infoENT = infoBLL.GetEntity(infoENT);
                }

                cust_cpENT = GetCust_CPValue(cust_cpENT);
                addressENT = GetAddressValue(addressENT);
                infoENT = GetInfoValue(infoENT);
                string LastModifyBy = Common.GetManageName();

                var AddToJobList = GetAddToJob();
                var DelToJobList = GetDelToJob();
                var AddToAttribute = GetAddToAttribute();
                var DelToAttribute = GetDelToAttribute();

                TransactionOptions options = new TransactionOptions();
                options.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
                options.Timeout = new TimeSpan(0, 5, 0);
                bool result = true;
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options))
                {
                    int cpCount = cpBLL.UpdateENT(cpENT);
                    int cust_cpCount = cust_cpBLL.UpdateENT(cust_cpENT);
                    int addCount = addressBLL.UpdateENT(addressENT);
                    int infoCount = infoBLL.UpdateENT(infoENT);
                    SaveCPImg();
                    //插入cp_attribute表
                    cp_attributeBLL.SaveList(AddToAttribute, DelToAttribute, cpuid, LastModifyBy);

                    cp_jobnatureBLL.SaveList(AddToJobList, DelToJobList, cpuid, LastModifyBy);

                    try
                    {
                        scope.Complete();
                    }
                    catch (Exception er)
                    {
                        result = false;
                    }
                }
                if (result)
                {
                    lblMeg.Text = ResourceManage.GetResourceString("msg200004");
                    Setcp_jobNature();
                    Setcp_attribure();
                }
                else
                { lblMeg.Text = ResourceManage.GetResourceString("msg200003"); }
            }
        }
        #endregion
        #region 添加按钮
        protected void AddCP()
        {
            cpENT = GetCPValue(cpENT);
            cust_cpENT = GetCust_CPValue(cust_cpENT);
            addressENT = GetAddressValue(addressENT);
            infoENT = GetInfoValue(infoENT);
            string LastModifyBy = Common.GetManageName();

            var AddToJobList = GetAddToJob();
            var DelToJobList = GetDelToJob();
            var AddToAttribute = GetAddToAttribute();
            var DelToAttribute = GetDelToAttribute();
            TransactionOptions options = new TransactionOptions();
            options.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
            options.Timeout = new TimeSpan(0, 3, 0);
            bool result = true;
            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options))
            {
                //插入ContactPerson表
                cpENT = cpBLL.InsertENTRetENT(cpENT);
                cpuid = cpENT.ContactPersonUID;

                //插入tblCust_ContactPerson关联表
                cust_cpENT.ContactPersonUID = cpuid;
                int cust_cpCount = cust_cpBLL.InsertENT(cust_cpENT);

                //插入address表
                int addressuid = addressBLL.InsertENT(addressENT);
                //插入info表
                int infouid = infoBLL.InsertENT(infoENT);
                //修改cpENT属性
                cpENT.ContactInfoUID = infouid;
                cpENT.AddressUID = addressuid;
                cpBLL.UpdateENT(cpENT);

                SaveCPImg();

                //插入cp_attribute表
                cp_attributeBLL.SaveList(AddToAttribute, DelToAttribute, cpuid, LastModifyBy);

                cp_jobnatureBLL.SaveList(AddToJobList, DelToJobList, cpuid, LastModifyBy);

                try
                {
                    scope.Complete();
                }
                catch (Exception er)
                {
                    result = false;
                }
            }
            if (result)
            {
                lblMeg.Text = ResourceManage.GetResourceString("msg200006");
                ScriptManager.RegisterStartupScript(this, this.GetType(), "cleartxt", "ClearText();", true);
            }
            else
            { lblMeg.Text = ResourceManage.GetResourceString("msg200005"); }
        }
        #endregion

        #region 页面初始化事件
        protected void InitPage()
        {
            tblCustomer customerENT = new tblCustomer();
            tblCustomerBLL customerBLL = new tblCustomerBLL();
            customerENT.CustomerUID = customeruid;
            customerENT = customerBLL.GetEntity(customerENT);
            if (customerENT != null)
            {
                type = Request.QueryString["type"];
                AddToDropList();
                BindPersonImg();
                BindActivityList();
                BindActivityName();
                BindSalutation();
                BindArea();
                BindAttributeList();
                BindJobNatureList();
                BindCommType();
                BindCommPosition();
                BindCPList(); //两者之间先后顺序不能反
                BindRelatedCPList();
                hdCustomerUID.Value = customeruid.ToString();
                if (Request.QueryString[Constant.UrlParamName.ContactPersonUID] != null)
                {
                    string str = Constant.UrlParamName.ContactPersonUID;
                    lkQuit.NavigateUrl = lkAdd.NavigateUrl = "ContactPerson.aspx?" + Constant.UrlParamName.CustomerUID + "=" + customeruid + "&type=add";
                    if (cpuid > 0)
                    {
                        //检测 CPUID与UID是否存在关联
                        cust_cpENT.ContactPersonUID = cpuid;
                        cust_cpENT.CustomerUID = customeruid;
                        cust_cpENT.Deleted = 0;
                        var temp = cust_cpBLL.GetEntity(cust_cpENT);
                        if (temp != null)
                        {
                            hdCPUID.Value = cpuid.ToString();
                            SetCust_ContactPerson(temp);
                            SetContactPerson();
                            Setcp_jobNature();
                            Setcp_attribure();
                            BingImgRelated(false);
                            isToCP = true;
                            BindCommitteeMember(isToCP);
                        }
                        else
                        {
                            SetNoOption();
                            lblMeg.Text = ResourceManage.GetResourceString("msg200012");
                        }
                    }
                    else
                    {
                        SetNoOption();
                        lblMeg.Text = ResourceManage.GetResourceString("msg200001");
                    }
                }
                else
                {
                    initInfo();
                }
            }
            else
            {
                SetNoOption();
                lblMeg.Text = ResourceManage.GetResourceString("msg200014");
            }
        }

        protected void SetNoOption()
        {
            initInfo();
            hidAllowToOption.Value = "false";
            lkbtnSave.Enabled = false;
        }
        #endregion

        #region 页面初始化控件绑定
        protected void BindActivityList()
        {
            mtblActiviteType typeENT = new mtblActiviteType();
            mtblActiviteTypeBLL typeBLL = new mtblActiviteTypeBLL();
            typeENT.Deleted = 0;
            var list = typeBLL.GetListByENT(typeENT);
            if (list.Count > 0)
            {
                ddlActivityType.DataSource = list;
                ddlActivityType.DataTextField = "ActiviteType_Eng";
                ddlActivityType.DataValueField = "ActiviteTypeUID";
                ddlActivityType.DataBind();
            }
        }

        protected void BindActivityName()
        {
            tblActivite activitENT = new tblActivite();
            tblActiviteBLL activiteBLL = new tblActiviteBLL();
            int UID = Convert.ToInt32(ddlActivityType.SelectedValue);
            activitENT.ActiviteTypeUID = UID;
            var list = activiteBLL.GetListByENT(activitENT);
            ddlActivityName.Items.Clear();
            if (list.Count > 0)
            {
                ddlActivityName.DataSource = list;
                ddlActivityName.DataTextField = "Activite_Name";
                ddlActivityName.DataValueField = "ActiviteUID";
                ddlActivityName.DataBind();
            }
            else
            {
                ListItem item = new ListItem();
                item.Text = ResourceManage.GetResourceString("msg200000");
                item.Value = "0";
                ddlActivityName.Items.Add(item);
            }
        }

        protected void BindSalutation()
        {
            mtblSalutation salutationENT = new mtblSalutation();
            mtblSalutationBLL salutationBLL = new mtblSalutationBLL();
            salutationENT.Deleted = 0;
            var list = salutationBLL.GetListByENT(salutationENT);
            ddlSalutation.DataSource = list;
            ddlSalutation.DataTextField = "Salutation_Eng";
            ddlSalutation.DataValueField = "SalutationUID";
            ddlSalutation.DataBind();
        }

        protected void BindArea()
        {
            mtblArea areaENT = new mtblArea();
            areaENT.Deleted = 0;
            mtblAreaBLL areaBLL = new mtblAreaBLL();
            var list = areaBLL.GetListByENT(areaENT);
            ddlArea.DataSource = list;
            ddlArea.DataTextField = "Area_Chi";
            ddlArea.DataValueField = "AreaUID";
            ddlArea.DataBind();
            BindCountry();
        }

        protected void BindAttributeList()
        {
            mtblAttribute attributeENT = new mtblAttribute();
            attributeENT.Deleted = 0;
            mtblAttributeBLL attributeBLL = new mtblAttributeBLL();
            var datasource = attributeBLL.GetAllByENT(attributeENT);
            ckbAttributeList.DataSource = datasource;
            ckbAttributeList.DataTextField = "FullName";
            ckbAttributeList.DataValueField = "AttributeUID";
            ckbAttributeList.DataBind();
        }

        protected void BindJobNatureList()
        {
            mtblJobNature jobNatureENT = new mtblJobNature();
            mtblJobNatureBLL jobNatureBLL = new mtblJobNatureBLL();
            jobNatureENT.Deleted = 0;
            var datasource = jobNatureBLL.GetListByENT(jobNatureENT);
            ckbJobNatureList.DataSource = datasource;
            ckbJobNatureList.DataTextField = "JobNature_Eng";
            ckbJobNatureList.DataValueField = "JobNatureUID";
            ckbJobNatureList.DataBind();
        }

        #region
        static List<mtblCommType> listCommType = new List<mtblCommType>();
        #endregion
        protected void BindCommType()
        {
            mtblCommType typeENT = new mtblCommType();
            mtblCommTypeBLL typeBLL = new mtblCommTypeBLL();
            typeENT.Deleted = 0;
            var source = typeBLL.GetListByENT(typeENT);
            listCommType = source;
            ddlCommType.DataSource = source;
            ddlCommType.DataTextField = "CommType_Eng";
            ddlCommType.DataValueField = "CommTypeUID";
            ddlCommType.DataBind();
        }
        #region
        static List<mtblCommPosition> listCommPosition = new List<mtblCommPosition>();
        #endregion
        protected void BindCommPosition()
        {
            mtblCommPosition commPositionENT = new mtblCommPosition();
            mtblCommPositionBLL commpositionBLL = new mtblCommPositionBLL();
            commPositionENT.Deleted = 0;
            var source = commpositionBLL.GetListByENT(commPositionENT);
            ddlCommPosition.DataSource = source;
            ddlCommPosition.DataTextField = "CommPosition_Eng";
            ddlCommPosition.DataValueField = "CommPositionUID";
            ddlCommPosition.DataBind();
            listCommPosition = source;
        }

        protected void BindPersonImg()
        {
            tblMediaRoom mediaroomENT = new tblMediaRoom();
            tblMediaRoomBLL mediaroomBLL = new tblMediaRoomBLL();
            mediaroomENT.CustomerUID = Convert.ToInt32(customeruid);
            mediaroomENT.IsPublish = 1;
            mediaroomENT.MediaType = Constant.MediaType.image;
            mediaroomENT.Category = Constant.MediaRoomCategory.contactperson_photo;
            var list = mediaroomBLL.GetListByENT(mediaroomENT);
            rptImgList.DataSource = list;
            rptImgList.DataBind();
        }

        private void AddToDropList()
        {
            Hashtable tellHas = Constant.InfoType.tellType;
            Hashtable FaxHas = Constant.InfoType.FaxType;
            Hashtable MailHas = Constant.InfoType.EmailType;
            Hashtable WebHas = Constant.InfoType.WebType;
            //telphone
            DropDownListTel1.DataSource = DropDownListTel2.DataSource = DropDownListTel3.DataSource = DropDownListTel4.DataSource = DropDownListTel5.DataSource = tellHas;
            DropDownListTel1.DataTextField = DropDownListTel2.DataTextField = DropDownListTel3.DataTextField = DropDownListTel4.DataTextField = DropDownListTel5.DataTextField = "value";
            DropDownListTel1.DataValueField = DropDownListTel2.DataValueField = DropDownListTel3.DataValueField = DropDownListTel4.DataValueField = DropDownListTel5.DataValueField = "key";
            DropDownListTel1.DataBind();
            DropDownListTel2.DataBind();
            DropDownListTel3.DataBind();
            DropDownListTel4.DataBind();
            DropDownListTel5.DataBind();
            //Fax
            DropDownListFax1.DataSource = DropDownListFax2.DataSource = DropDownListFax3.DataSource = DropDownListFax4.DataSource = DropDownListFax5.DataSource = FaxHas;
            DropDownListFax1.DataTextField = DropDownListFax2.DataTextField = DropDownListFax3.DataTextField = DropDownListFax4.DataTextField = DropDownListFax5.DataTextField = "value";
            DropDownListFax1.DataValueField = DropDownListFax2.DataValueField = DropDownListFax3.DataValueField = DropDownListFax4.DataValueField = DropDownListFax5.DataValueField = "key";
            DropDownListFax1.DataBind();
            DropDownListFax2.DataBind();
            DropDownListFax3.DataBind();
            DropDownListFax4.DataBind();
            DropDownListFax5.DataBind();
            //Mail
            DropDownListEm1.DataSource = DropDownListEm2.DataSource = DropDownListEm3.DataSource = DropDownListEm4.DataSource = DropDownListEm5.DataSource = MailHas;
            DropDownListEm1.DataTextField = DropDownListEm2.DataTextField = DropDownListEm3.DataTextField = DropDownListEm4.DataTextField = DropDownListEm5.DataTextField = "value";
            DropDownListEm1.DataValueField = DropDownListEm2.DataValueField = DropDownListEm3.DataValueField = DropDownListEm4.DataValueField = DropDownListEm5.DataValueField = "key";
            DropDownListEm1.DataBind();
            DropDownListEm2.DataBind();
            DropDownListEm3.DataBind();
            DropDownListEm4.DataBind();
            DropDownListEm5.DataBind();
            //WEBsit
            DropDownListW1.DataSource = DropDownListW2.DataSource = WebHas;
            DropDownListW1.DataTextField = DropDownListW2.DataTextField = "value";
            DropDownListW1.DataValueField = DropDownListW2.DataValueField = "key";
            DropDownListW1.DataBind();
            DropDownListW2.DataBind();
        }
        /// 新添加时 Contact Information 的样子
        private void initInfo()
        {
            //telephone
            PanelT1.Visible = true;
            PanelT2.Style.Add("display", "none");
            PanelT3.Style.Add("display", "none");
            PanelT4.Style.Add("display", "none");
            PanelT5.Style.Add("display", "none");

            //fax
            PanelF1.Visible = true;
            PanelF2.Style.Add("display", "none");
            PanelF3.Style.Add("display", "none");
            PanelF4.Style.Add("display", "none");
            PanelF5.Style.Add("display", "none");

            //email
            PanelE1.Visible = true;
            PanelE2.Style.Add("display", "none");
            PanelE3.Style.Add("display", "none");
            PanelE4.Style.Add("display", "none");
            PanelE5.Style.Add("display", "none");

            //website
            PanelW1.Visible = true;
            PanelW2.Style.Add("display", "none");


        }

        protected void BindCPList()
        {
            tblCust_ContactPerson cust_CPENT = new tblCust_ContactPerson();
            tblCust_ContactPersonBLL cust_CPBLL = new tblCust_ContactPersonBLL();
            cust_CPENT.CustomerUID = customeruid;
            var list = cpList = cust_CPBLL.GetCPListDetail(customeruid);
            if (list.Count > 0)
            {
                rptCPList.DataSource = list;
                rptCPList.DataBind();
                ScriptManager.RegisterStartupScript(this, this.GetType(), "myscript", "AverageBrand();", true);
            }
        }

        protected void BindRelatedCPList()
        {
            if (cpList.Count > 0)
            {
                ListItem itemF = new ListItem();
                itemF.Text = "请选择";
                itemF.Value = "0";
                ddlRelatedCP.Items.Clear();
                ddlRelatedCP.Items.Add(itemF);
                foreach (var temp in cpList)
                {
                    if (cpuid <= 0 || temp.CPUID != cpuid)
                    {
                        ListItem item = new ListItem();
                        item.Text = temp.FullName;
                        item.Value = temp.CPUID.ToString();
                        ddlRelatedCP.Items.Add(item);
                    }
                }
            }
            else
            {
                ListItem itemF = new ListItem();
                itemF.Text = "暂无数据.";
                itemF.Value = "0";
                ddlRelatedCP.Items.Add(itemF);
            }
            ddlRelatedCP.SelectedValue = "0";
        }


        protected void BindCommitteeMember(bool isToCP)
        {

            tblCust_ContactPerson cust_CPENT = new tblCust_ContactPerson();
            tblCust_ContactPersonBLL cust_CPBLL = new tblCust_ContactPersonBLL();
            cust_CPENT.CustomerUID = customeruid;
            if (cpuid > 0)
                cust_CPENT.ContactPersonUID = cpuid;
            cust_CPENT.Deleted = 0;
            tblCPerson_CommMemberBLL cp_commBLL = new tblCPerson_CommMemberBLL();
            var list = cp_commBLL.GetListByCust_CPerson(cust_CPENT, isToCP).OrderByDescending(a => a.Cperson_CommMemberUID);
            rptCommitteeMember.DataSource = list;
            rptCommitteeMember.DataBind();
        }

        protected void BindCountry()
        {
            mtblCountry countryENT = new mtblCountry();
            mtblCountryBLL countryBLL = new mtblCountryBLL();
            countryENT.Deleted = 0;
            int areaUID = Convert.ToInt32(ddlArea.SelectedValue);
            countryENT.AreaUID = areaUID;
            var list = countryBLL.GetListByENT(countryENT);
            if (list.Count > 0)
            {
                ddlCountry.DataSource = list;
                ddlCountry.DataTextField = "Country_Chi";
                ddlCountry.DataValueField = "CountryUID";
                ddlCountry.DataBind();
            }
        }
        #endregion

        #region 页面初始化ContactPerson信息
        protected void SetContactPerson()
        {
            cpENT.ContactPersonUID = cpuid;
            cpENT = cpBLL.GetEntity(cpENT);
            if (cpENT != null)
            {
                txtChristianName.Text = cpENT.ChristianName;
                txtFirstName_Eng.Text = cpENT.FirstName_Eng;
                txtLastName_Eng.Text = cpENT.LastName_Eng;
                txtOtherTitle_Eng.Text = cpENT.OtherTitle_Eng;
                txtFirstName_Chi.Text = cpENT.FirstName_Chi;
                txtLastName_Chi.Text = cpENT.LastName_Chi;
                txtOtherTitle_Chi.Text = cpENT.OtherTitle_Chi;
                hidTxtHKID.Value = cpENT.HKID_PassportID;

                txtRelationship.Text = cpENT.Relationship;
                if (cpENT.RelatedContactPersonUID > 0)
                    ddlRelatedCP.SelectedValue = cpENT.RelatedContactPersonUID.ToString();
                txtRemark.Text = cpENT.Remark;

                if (cpENT.ActivityUID > 0)
                {
                    tblActivite actENT = new tblActivite();
                    tblActiviteBLL actBLL = new tblActiviteBLL();

                    actENT.ActiviteUID = (int)cpENT.ActivityUID;
                    actENT = actBLL.GetEntity(actENT);
                    if (actENT != null)
                    {
                        if (actENT.ActiviteTypeUID > 0)
                            ddlActivityType.SelectedValue = actENT.ActiviteTypeUID.ToString();
                    }
                    BindActivityName();
                    ddlActivityName.SelectedValue = cpENT.ActivityUID.ToString();
                }

                if (cpENT.AddressUID != null)
                { SetAddress((int)cpENT.AddressUID); }

                if (cpENT.ContactInfoUID != null)
                { SetInfo((int)cpENT.ContactInfoUID); }
            }
        }
        protected void BingImgRelated(bool isPostBack)
        {
            tblMediaRoom_Related relatedENT = new tblMediaRoom_Related();
            tblMediaRoomRelatedBLL relatedBLL = new tblMediaRoomRelatedBLL();
            relatedENT.Category = Constant.MediaRoomCategory.contactperson_photo;
            relatedENT.RelatedUID = cpuid;
            relatedENT.Deleted = 0;
            var list = relatedBLL.GetListWithMediaRoomByENT(relatedENT);
            var source = new List<Ext_MediaRoom>();
            var ent = list.FirstOrDefault(); //只允许一个
            if (ent != null)
            {
                hidMediaRoomUID.Value = ent.MediaRoomUID.ToString();
                hidMediaRoomRelatedUID.Value = ent.MediaRoomRelatedUID.ToString();
                source.Add(ent);
            }
            //if (list.Count > 0)
            //{
            //    var count = list.Count;
            //    for (int i = 0; i < count; i++)
            //    {
            //        //记录原始已经关联的MediaRoomUID, 方便Save事件过滤掉 新增关联MediaRoomUID 确未保存到数据库 的记录
            //        //hidRelatedMediastrUID.Value += list[i].MediaRoomUID.ToString() + ",";
            //    }
            //}           
            if (!isPostBack)
            {
                rptRelatedImgList.DataSource = source;
                rptRelatedImgList.DataBind();
            }
        }
        protected void SetCust_ContactPerson(tblCust_ContactPerson ent)
        {
            txtPosition_Chi.Text = ent.Position_Chi;
            txtPosition_Eng.Text = ent.Position_Eng;
        }

        protected void SetAddress(int addUID)
        {
            addressENT.AddressUID = addUID;
            addressENT = addressBLL.GetEntity(addressENT);
            if (addressENT != null)
            {
                hidAddressUID.Value = addressENT.AddressUID.ToString();
                txtArea_Chi.Text = addressENT.Area_Chi;
                txtArea_Eng.Text = addressENT.Area_Eng;
                txtCity_Chi.Text = addressENT.City_Chi;
                txtCity_Eng.Text = addressENT.City_Eng;
                if (addressENT.CountryUID != null)
                {
                    if (addressENT.mtblCountry.AreaUID != null)
                    {
                        ddlArea.SelectedValue = addressENT.mtblCountry.AreaUID.ToString();
                    }
                    BindCountry();
                    ddlCountry.SelectedValue = addressENT.CountryUID.ToString();

                }
                txtDistrict_Chi.Text = addressENT.District_Chi;
                txtDistrict_Eng.Text = addressENT.District_Eng;
                txtFlat_Chi.Text = addressENT.Flat_Bldg_Chi;
                txtFlat_Eng.Text = addressENT.Flat_Bldg_Eng;
                txtPostCode.Text = addressENT.PostalCode;
                txtProvince_Chi.Text = addressENT.Province_Chi;
                txtProvince_Eng.Text = addressENT.Province_Eng;
                txtStreet_Chi.Text = addressENT.Street_Rd_Chi;
                txtStreet_Eng.Text = addressENT.Street_Rd_Eng;
                txtDepartment_Chi.Text = addressENT.Department_Chi;
                txtDepartment_Eng.Text = addressENT.Department_Eng;
            }
        }

        private void SetInfo(int infoUID)
        {
            infoENT.ContactInfoUID = infoUID;
            infoENT = infoBLL.GetEntity(infoENT);
            if (infoENT != null)
            {
                hidInfoUID.Value = infoENT.ContactInfoUID.ToString();
                #region Info
                DropDownListTel1.SelectedValue = infoENT.Tel1_Type.ToString();
                TextBoxTC1.Text = infoENT.Tel1_CountryCode;
                TextBoxTA1.Text = infoENT.Tel1_AreaCode;
                TextBoxT1.Text = infoENT.Tel1;
                CheckBoxTD1.Checked = infoENT.Tel1_IsDNC == 1 ? true : false;
                CheckBoxTS1.Checked = infoENT.Tel1_IsSubscribe == 1 ? true : false;

                if (string.IsNullOrEmpty(infoENT.Tel1_CountryCode) && string.IsNullOrEmpty(infoENT.Tel1_AreaCode) && string.IsNullOrEmpty(infoENT.Tel1))
                {
                    PanelT1.Style.Add("display", "none");
                    telNum--;
                }

                DropDownListTel2.SelectedValue = infoENT.Tel2_Type.ToString();
                TextBoxTC2.Text = infoENT.Tel2_CountryCode;
                TextBoxTA2.Text = infoENT.Tel2_AreaCode;
                TextBoxT2.Text = infoENT.Tel2;
                CheckBoxTD2.Checked = infoENT.Tel2_IsDNC == 1 ? true : false;
                CheckBoxTS2.Checked = infoENT.Tel2_IsSubscribe == 1 ? true : false;
                if (string.IsNullOrEmpty(infoENT.Tel2_CountryCode) && string.IsNullOrEmpty(infoENT.Tel2_AreaCode) && string.IsNullOrEmpty(infoENT.Tel2))
                {
                    PanelT2.Style.Add("display", "none");
                    telNum--;
                }



                DropDownListTel3.SelectedValue = infoENT.Tel3_Type.ToString();
                TextBoxTC3.Text = infoENT.Tel3_CountryCode;
                TextBoxTA3.Text = infoENT.Tel3_AreaCode;
                TextBoxT3.Text = infoENT.Tel3;
                CheckBoxTD3.Checked = infoENT.Tel3_IsDNC == 1 ? true : false;
                CheckBoxTS3.Checked = infoENT.Tel3_IsSubscribe == 1 ? true : false;
                if (string.IsNullOrEmpty(infoENT.Tel3_CountryCode) && string.IsNullOrEmpty(infoENT.Tel3_AreaCode) && string.IsNullOrEmpty(infoENT.Tel3))
                {
                    PanelT3.Style.Add("display", "none");
                    telNum--;
                }

                DropDownListTel4.SelectedValue = infoENT.Tel4_Type.ToString();
                TextBoxTC4.Text = infoENT.Tel4_CountryCode;
                TextBoxTA4.Text = infoENT.Tel4_AreaCode;
                TextBoxT4.Text = infoENT.Tel4;
                CheckBoxTD4.Checked = infoENT.Tel4_IsDNC == 1 ? true : false;
                CheckBoxTS4.Checked = infoENT.Tel4_IsSubscribe == 1 ? true : false;
                if (string.IsNullOrEmpty(infoENT.Tel4_CountryCode) && string.IsNullOrEmpty(infoENT.Tel4_AreaCode) && string.IsNullOrEmpty(infoENT.Tel4))
                {
                    PanelT4.Style.Add("display", "none");
                    telNum--;
                }

                DropDownListTel5.SelectedValue = infoENT.Tel5_Type.ToString();
                TextBoxTC5.Text = infoENT.Tel5_CountryCode;
                TextBoxTA5.Text = infoENT.Tel5_AreaCode;
                TextBoxT5.Text = infoENT.Tel5;
                CheckBoxTD5.Checked = infoENT.Tel5_IsDNC == 1 ? true : false;
                CheckBoxTS5.Checked = infoENT.Tel5_IsSubscribe == 1 ? true : false;
                if (string.IsNullOrEmpty(infoENT.Tel5_CountryCode) && string.IsNullOrEmpty(infoENT.Tel5_AreaCode) && string.IsNullOrEmpty(infoENT.Tel5))
                {
                    PanelT5.Style.Add("display", "none");
                    telNum--;
                }
                if (telNum <= 0)
                    PanelT5.Style.Add("display", "true");
                #endregion

                #region Fax
                //Fax
                DropDownListFax1.SelectedValue = infoENT.Fax1_Type.ToString();
                TextBoxFC1.Text = infoENT.Fax1_CountryCode;
                TextBoxFA1.Text = infoENT.Fax1_AreaCode;
                TextBoxF1.Text = infoENT.Fax1;
                CheckBoxFD1.Checked = infoENT.Fax1_IsDNC == 1 ? true : false;
                CheckBoxFS1.Checked = infoENT.Fax1_IsSubscribe == 1 ? true : false;
                if (string.IsNullOrEmpty(infoENT.Fax1) && string.IsNullOrEmpty(infoENT.Fax1_AreaCode) && string.IsNullOrEmpty(infoENT.Fax2_CountryCode))
                {
                    PanelF1.Style.Add("display", "none");
                    faxNum--;
                }


                DropDownListFax2.SelectedValue = infoENT.Fax2_Type.ToString();
                TextBoxFC2.Text = infoENT.Fax2_CountryCode;
                TextBoxFA2.Text = infoENT.Fax2_AreaCode;
                TextBoxF2.Text = infoENT.Fax2;
                CheckBoxFD2.Checked = infoENT.Fax2_IsDNC == 1 ? true : false;
                CheckBoxFS2.Checked = infoENT.Fax2_IsSubscribe == 1 ? true : false;
                if (string.IsNullOrEmpty(infoENT.Fax2) && string.IsNullOrEmpty(infoENT.Fax2_AreaCode) && string.IsNullOrEmpty(infoENT.Fax2_CountryCode))
                {
                    PanelF2.Style.Add("display", "none");
                    faxNum--;
                }




                DropDownListFax3.SelectedValue = infoENT.Fax3_Type.ToString();
                TextBoxFC3.Text = infoENT.Fax3_CountryCode;
                TextBoxFA3.Text = infoENT.Fax3_AreaCode;
                TextBoxF3.Text = infoENT.Fax3;
                CheckBoxFD3.Checked = infoENT.Fax3_IsDNC == 1 ? true : false;
                CheckBoxFS3.Checked = infoENT.Fax3_IsSubscribe == 1 ? true : false;
                if (string.IsNullOrEmpty(infoENT.Fax3) && string.IsNullOrEmpty(infoENT.Fax3_AreaCode) && string.IsNullOrEmpty(infoENT.Fax3_CountryCode))
                {
                    PanelF3.Style.Add("display", "none");
                    faxNum--;
                }


                DropDownListFax4.SelectedValue = infoENT.Fax4_Type.ToString();
                TextBoxFC4.Text = infoENT.Fax4_CountryCode;
                TextBoxFA4.Text = infoENT.Fax4_AreaCode;
                TextBoxF4.Text = infoENT.Fax4;
                CheckBoxFD4.Checked = infoENT.Fax4_IsDNC == 1 ? true : false;
                CheckBoxFS4.Checked = infoENT.Fax4_IsSubscribe == 1 ? true : false;
                if (string.IsNullOrEmpty(infoENT.Fax4) && string.IsNullOrEmpty(infoENT.Fax4_AreaCode) && string.IsNullOrEmpty(infoENT.Fax4_CountryCode))
                {
                    PanelF4.Style.Add("display", "none");
                    faxNum--;
                }


                DropDownListFax5.SelectedValue = infoENT.Fax5_Type.ToString();
                TextBoxFC5.Text = infoENT.Fax5_CountryCode;
                TextBoxFA5.Text = infoENT.Fax5_AreaCode;
                TextBoxF5.Text = infoENT.Fax5;
                CheckBoxFD5.Checked = infoENT.Fax5_IsDNC == 1 ? true : false;
                CheckBoxFS5.Checked = infoENT.Fax5_IsSubscribe == 1 ? true : false;
                if (string.IsNullOrEmpty(infoENT.Fax5) && string.IsNullOrEmpty(infoENT.Fax5_AreaCode) && string.IsNullOrEmpty(infoENT.Fax5_CountryCode))
                {
                    PanelF5.Style.Add("display", "none");
                    faxNum--;
                }
                if (faxNum <= 0)
                    PanelF1.Style.Add("display", "true");
                #endregion
                #region Email
                //email 
                DropDownListEm1.SelectedValue = infoENT.Email1_Type.ToString();
                TextBoxEmail1.Text = infoENT.Email1;
                CheckBoxES1.Checked = infoENT.Email1_IsSubscribe == 1 ? true : false;
                CheckBoxHB1.Checked = infoENT.Email1_HardBounce == 1 ? true : false;
                if (string.IsNullOrEmpty(infoENT.Email1))
                {
                    PanelE5.Style.Add("display", "none");
                    emailNum--;
                }



                DropDownListEm2.SelectedValue = infoENT.Email2_Type.ToString();
                TextBoxEmail2.Text = infoENT.Email2;
                CheckBoxES2.Checked = infoENT.Email2_IsSubscribe == 1 ? true : false;
                CheckBoxHB2.Checked = infoENT.Email2_HardBounce == 1 ? true : false;
                if (string.IsNullOrEmpty(infoENT.Email2))
                {
                    PanelE2.Style.Add("display", "none");
                    emailNum--;
                }

                DropDownListEm3.SelectedValue = infoENT.Email3_Type.ToString();
                TextBoxEmail3.Text = infoENT.Email3;
                CheckBoxES3.Checked = infoENT.Email3_IsSubscribe == 1 ? true : false;
                CheckBoxHB3.Checked = infoENT.Email3_HardBounce == 1 ? true : false;
                if (string.IsNullOrEmpty(infoENT.Email3))
                {
                    PanelE3.Style.Add("display", "none");
                    emailNum--;
                }

                DropDownListEm4.SelectedValue = infoENT.Email4_Type.ToString();
                TextBoxEmail4.Text = infoENT.Email4;
                CheckBoxES4.Checked = infoENT.Email4_IsSubscribe == 1 ? true : false;
                CheckBoxHB4.Checked = infoENT.Email4_HardBounce == 1 ? true : false;
                if (string.IsNullOrEmpty(infoENT.Email4))
                {
                    PanelE4.Style.Add("display", "none");
                    emailNum--;
                }


                DropDownListEm5.SelectedValue = infoENT.Email5_Type.ToString();
                TextBoxEmail5.Text = infoENT.Email5;
                CheckBoxES5.Checked = infoENT.Email5_IsSubscribe == 1 ? true : false;
                CheckBoxHB5.Checked = infoENT.Email5_HardBounce == 1 ? true : false;
                if (string.IsNullOrEmpty(infoENT.Email5))
                {
                    PanelE5.Style.Add("display", "none");
                    emailNum--;
                }
                if (emailNum <= 0)
                    PanelE1.Style.Add("display", "true");
                #endregion
                #region WebSite
                //website
                DropDownListW1.SelectedValue = infoENT.Website1_Type.ToString();
                TextBoxWeb1.Text = infoENT.Website1;
                if (string.IsNullOrEmpty(infoENT.Website2))
                {
                    PanelW1.Style.Add("display", "none");
                    webNum--;
                }
                DropDownListW2.SelectedValue = infoENT.Website2_Type.ToString();
                TextBoxWeb2.Text = infoENT.Website2;
                if (string.IsNullOrEmpty(infoENT.Website2))
                {
                    PanelW2.Style.Add("display", "none");
                    webNum--;
                }
                if (webNum <= 0)
                    PanelW1.Style.Add("display", "true");
                #endregion
            }
            else
            {
                initInfo();
            }
        }

        protected void Setcp_jobNature()
        {
            cp_jobENT.ContactPersonUID = cpuid;
            cp_jobENT.Deleted = 0;
            var list = cp_jobnatureBLL.GetListByENT(cp_jobENT);
            string str = string.Empty;
            foreach (var tempENT in list)
            {
                str += tempENT.JobNatureUID + ",";
                for (int i = 0; i < ckbJobNatureList.Items.Count; i++)
                {
                    if (tempENT.JobNatureUID == Convert.ToInt32(ckbJobNatureList.Items[i].Value))
                    {
                        ckbJobNatureList.Items[i].Selected = true;
                        break;
                    }
                }
            }
            hidJobNatureUID.Value = str;
        }

        protected void Setcp_attribure()
        {
            cp_attributeENT.ContactPersonUID = cpuid;
            var list = cp_attributeBLL.GetListByENT(cp_attributeENT);
            string str = string.Empty;
            foreach (var tempENT in list)
            {
                str += tempENT.AttributeUID + ",";
                for (int i = 0; i < ckbAttributeList.Items.Count; i++)
                {
                    if (tempENT.AttributeUID.ToString() == ckbAttributeList.Items[i].Value)
                    {
                        ckbAttributeList.Items[i].Selected = true;
                        break;
                    }
                }
            }
            hidAttributeUID.Value = str;
        }
        #endregion

        #region 获取实体值
        protected tblContactPerson GetCPValue(tblContactPerson cpENT)
        {
            cpENT.SalutationUID = Convert.ToInt32(ddlSalutation.SelectedValue);
            cpENT.ChristianName = txtChristianName.Text;
            cpENT.FirstName_Eng = txtFirstName_Eng.Text;
            cpENT.LastName_Eng = txtLastName_Eng.Text;
            cpENT.OtherTitle_Eng = txtOtherTitle_Eng.Text;
            cpENT.FirstName_Chi = txtFirstName_Chi.Text;
            cpENT.LastName_Chi = txtLastName_Chi.Text;
            cpENT.OtherTitle_Chi = txtOtherTitle_Chi.Text;
            cpENT.CreationDate = DateTime.Now;
            cpENT.LastModifyDate = DateTime.Now;
            cpENT.LastModifyBy = Common.GetManageName();
            cpENT.ActivityUID = Convert.ToInt32(ddlActivityName.SelectedValue);
            cpENT.Relationship = txtRelationship.Text;
            cpENT.Remark = txtRemark.Text;
            //int relatedcpuid=0;
            //int.TryParse(txtRelatedCP.Text,out relatedcpuid);
            if (Convert.ToInt32(ddlRelatedCP.SelectedValue) > 0)
            {
                cpENT.RelatedContactPersonUID = Convert.ToInt32(ddlRelatedCP.SelectedValue);
            }

            cpENT.HKID_PassportID = hidTxtHKID.Value;
            return cpENT;
        }

        protected tblCust_ContactPerson GetCust_CPValue(tblCust_ContactPerson cust_cpENT)
        {
            cust_cpENT.CreationDate = DateTime.Now;
            cust_cpENT.LastModifyDate = DateTime.Now;
            cust_cpENT.CustomerUID = customeruid;
            cust_cpENT.ContactPersonUID = cpuid;
            cust_cpENT.Deleted = 0;
            cust_cpENT.LastModifyBy = Common.GetManageName();
            cust_cpENT.LastModifyDate = DateTime.Now;
            cust_cpENT.Position_Eng = txtPosition_Eng.Text;
            cust_cpENT.Position_Chi = txtPosition_Chi.Text;
            return cust_cpENT;
        }

        private tblContactInfo GetInfoValue(tblContactInfo infoENT)
        {
            #region Email
            infoENT.Email1 = TextBoxEmail1.Text;
            infoENT.Email1_IsSubscribe = CheckBoxES1.Checked ? 1 : 0;
            infoENT.Email1_Type = Convert.ToInt32(DropDownListEm1.SelectedValue);
            infoENT.Email1_HardBounce = CheckBoxHB1.Checked ? 1 : 0;
            infoENT.Email2 = TextBoxEmail2.Text;
            infoENT.Email2_IsSubscribe = CheckBoxES2.Checked ? 1 : 0;
            infoENT.Email2_Type = Convert.ToInt32(DropDownListEm2.SelectedValue);
            infoENT.Email2_HardBounce = CheckBoxHB2.Checked ? 1 : 0;
            infoENT.Email3 = TextBoxEmail3.Text;
            infoENT.Email3_IsSubscribe = CheckBoxES3.Checked ? 1 : 0;
            infoENT.Email3_Type = Convert.ToInt32(DropDownListEm3.SelectedValue);
            infoENT.Email3_HardBounce = CheckBoxHB3.Checked ? 1 : 0;
            infoENT.Email4 = TextBoxEmail4.Text;
            infoENT.Email4_IsSubscribe = CheckBoxES4.Checked ? 1 : 0;
            infoENT.Email4_Type = Convert.ToInt32(DropDownListEm4.SelectedValue);
            infoENT.Email4_HardBounce = CheckBoxHB4.Checked ? 1 : 0;
            infoENT.Email5 = TextBoxEmail5.Text;
            infoENT.Email5_IsSubscribe = CheckBoxES5.Checked ? 1 : 0;
            infoENT.Email5_Type = Convert.ToInt32(DropDownListEm5.SelectedValue);
            infoENT.Email5_HardBounce = CheckBoxHB5.Checked ? 1 : 0;
            #endregion
            #region Fax
            infoENT.Fax1 = TextBoxF1.Text;
            infoENT.Fax1_AreaCode = TextBoxFA1.Text;
            infoENT.Fax1_CountryCode = TextBoxFC1.Text;
            infoENT.Fax1_IsDNC = CheckBoxFD1.Checked ? 1 : 0;
            infoENT.Fax1_IsSubscribe = CheckBoxFS1.Checked ? 1 : 0;
            infoENT.Fax1_Type = Convert.ToInt32(DropDownListFax1.SelectedValue);

            infoENT.Fax2 = TextBoxF2.Text;
            infoENT.Fax2_AreaCode = TextBoxFA2.Text;
            infoENT.Fax2_CountryCode = TextBoxFC2.Text;
            infoENT.Fax2_IsDNC = CheckBoxFD2.Checked ? 1 : 0;
            infoENT.Fax2_IsSubscribe = CheckBoxFS2.Checked ? 1 : 0;
            infoENT.Fax2_Type = Convert.ToInt32(DropDownListFax2.SelectedValue);

            infoENT.Fax3 = TextBoxF3.Text;
            infoENT.Fax3_AreaCode = TextBoxFA3.Text;
            infoENT.Fax3_CountryCode = TextBoxFC3.Text;
            infoENT.Fax3_IsDNC = CheckBoxFD3.Checked ? 1 : 0;
            infoENT.Fax3_IsSubscribe = CheckBoxFS3.Checked ? 1 : 0;
            infoENT.Fax3_Type = Convert.ToInt32(DropDownListFax3.SelectedValue);

            infoENT.Fax4 = TextBoxF4.Text;
            infoENT.Fax4_AreaCode = TextBoxFA4.Text;
            infoENT.Fax4_CountryCode = TextBoxFC4.Text;
            infoENT.Fax4_IsDNC = CheckBoxFD4.Checked ? 1 : 0;
            infoENT.Fax4_IsSubscribe = CheckBoxFS4.Checked ? 1 : 0;
            infoENT.Fax4_Type = Convert.ToInt32(DropDownListFax4.SelectedValue);

            infoENT.Fax5 = TextBoxF5.Text;
            infoENT.Fax5_AreaCode = TextBoxFA5.Text;
            infoENT.Fax5_CountryCode = TextBoxFC5.Text;
            infoENT.Fax5_IsDNC = CheckBoxFD5.Checked ? 1 : 0;
            infoENT.Fax5_IsSubscribe = CheckBoxFS5.Checked ? 1 : 0;
            infoENT.Fax5_Type = Convert.ToInt32(DropDownListFax5.SelectedValue);
            #endregion
            #region Tel
            infoENT.Tel1 = TextBoxT1.Text;
            infoENT.Tel1_AreaCode = TextBoxTA1.Text;
            infoENT.Tel1_CountryCode = TextBoxTC1.Text;
            infoENT.Tel1_IsDNC = CheckBoxTD1.Checked ? 1 : 0;
            infoENT.Tel1_IsSubscribe = CheckBoxTS1.Checked ? 1 : 0;
            infoENT.Tel1_Type = Convert.ToInt32(DropDownListTel1.SelectedValue);

            infoENT.Tel2 = TextBoxT2.Text;
            infoENT.Tel2_AreaCode = TextBoxTA2.Text;
            infoENT.Tel2_CountryCode = TextBoxTC2.Text;
            infoENT.Tel2_IsDNC = CheckBoxTD2.Checked ? 1 : 0;
            infoENT.Tel2_IsSubscribe = CheckBoxTS2.Checked ? 1 : 0;
            infoENT.Tel2_Type = Convert.ToInt32(DropDownListTel2.SelectedValue);

            infoENT.Tel3 = TextBoxT3.Text;
            infoENT.Tel3_AreaCode = TextBoxTA3.Text;
            infoENT.Tel3_CountryCode = TextBoxTC3.Text;
            infoENT.Tel3_IsDNC = CheckBoxTD3.Checked ? 1 : 0;
            infoENT.Tel3_IsSubscribe = CheckBoxTS3.Checked ? 1 : 0;
            infoENT.Tel3_Type = Convert.ToInt32(DropDownListTel3.SelectedValue);

            infoENT.Tel4 = TextBoxT4.Text;
            infoENT.Tel4_AreaCode = TextBoxTA4.Text;
            infoENT.Tel4_CountryCode = TextBoxTC4.Text;
            infoENT.Tel4_IsDNC = CheckBoxTD4.Checked ? 1 : 0;
            infoENT.Tel4_IsSubscribe = CheckBoxTS4.Checked ? 1 : 0;
            infoENT.Tel4_Type = Convert.ToInt32(DropDownListTel4.SelectedValue);

            infoENT.Tel5 = TextBoxT5.Text;
            infoENT.Tel5_AreaCode = TextBoxTA5.Text;
            infoENT.Tel5_CountryCode = TextBoxTC5.Text;
            infoENT.Tel5_IsDNC = CheckBoxTD5.Checked ? 1 : 0;
            infoENT.Tel5_IsSubscribe = CheckBoxTS5.Checked ? 1 : 0;
            infoENT.Tel5_Type = Convert.ToInt32(DropDownListTel5.SelectedValue);
            #endregion

            #region WebSite
            infoENT.Website1 = TextBoxWeb1.Text;
            infoENT.Website1_Type = Convert.ToInt32(DropDownListW1.SelectedValue);
            infoENT.Website2 = TextBoxWeb2.Text;
            infoENT.Website2_Type = Convert.ToInt32(DropDownListW2.SelectedValue);
            #endregion
            return infoENT;
        }

        protected List<int> GetAddToJob()
        { return GetList(hidAddToJob); }

        protected List<int> GetDelToJob()
        { return GetList(hidDelToJob); }

        protected List<int> GetAddToAttribute()
        { return GetList(hidAddToAttribute); }

        protected List<int> GetDelToAttribute()
        { return GetList(hidDelToAttribute); }

        protected List<int> GetList(HiddenField name)
        {
            List<int> ret = new List<int>();
            if (!string.IsNullOrEmpty(name.Value))
            {
                ret = name.Value.StringToList();
            }
            return ret;
        }

        protected tblAddress GetAddressValue(tblAddress addressENT)
        {
            addressENT.Area_Chi = txtArea_Chi.Text;
            addressENT.Area_Eng = txtArea_Eng.Text;
            addressENT.City_Chi = txtCity_Chi.Text;
            addressENT.City_Eng = txtCity_Eng.Text;
            addressENT.CountryUID = Convert.ToInt32(ddlCountry.SelectedValue);
            addressENT.CreationDate = DateTime.Now;
            addressENT.District_Chi = txtDistrict_Chi.Text;
            addressENT.District_Eng = txtDistrict_Eng.Text;
            addressENT.Flat_Bldg_Chi = txtFlat_Chi.Text;
            addressENT.Flat_Bldg_Eng = txtFlat_Eng.Text;
            addressENT.LastModifyBy = Common.GetManageName();
            addressENT.LastModifyDate = DateTime.Now;
            addressENT.PostalCode = txtPostCode.Text;
            addressENT.Province_Chi = txtProvince_Chi.Text;
            addressENT.Province_Eng = txtProvince_Eng.Text;
            addressENT.Street_Rd_Chi = txtStreet_Chi.Text;
            addressENT.Street_Rd_Eng = txtStreet_Eng.Text;
            addressENT.Department_Chi = txtDepartment_Chi.Text;
            addressENT.Department_Eng = txtDepartment_Eng.Text;
            mtblCountry countryENT = new mtblCountry();
            countryENT = addressENT.mtblCountry;
            StringBuilder strBuilderEng = new StringBuilder();
            strBuilderEng.Append(txtFlat_Eng.Text).Append(txtStreet_Eng.Text).Append(txtArea_Eng.Text).Append(txtDistrict_Eng.Text).Append(txtCity_Eng.Text).Append(txtProvince_Eng.Text);
            StringBuilder strBuilderChi = new StringBuilder();
            if (countryENT != null)
            {
                strBuilderEng.Append(countryENT.Country_Eng);

                if (countryENT.AreaUID > 0)
                {
                    mtblArea areaENT = new mtblArea();
                    areaENT.AreaUID = (int)countryENT.AreaUID;
                    mtblAreaBLL bll = new mtblAreaBLL();
                    areaENT = bll.GetEntity(areaENT);
                    if (areaENT != null)
                    {
                        strBuilderEng.Append(areaENT.Area_Eng);
                        strBuilderChi.Append(areaENT.Area_Chi);
                    }
                }
                strBuilderChi.Append(countryENT.Country_Chi);
            }
            strBuilderChi.Append(txtProvince_Chi.Text).Append(txtCity_Chi.Text).Append(txtDistrict_Chi.Text).Append(txtArea_Chi.Text).Append(txtStreet_Chi.Text).Append(txtFlat_Chi.Text);
            addressENT.FullAdd_Chi = strBuilderChi.ToString();
            addressENT.FullAdd_Eng = strBuilderEng.ToString();
            return addressENT;
        }

        #endregion

        #region 绑定事件

        protected void SaveCPImg()
        {
            int MediaRoomUID = 0;
            int RelatedUID = 0;
            int.TryParse(hidMediaRoomUID.Value, out MediaRoomUID);
            int.TryParse(hidMediaRoomRelatedUID.Value, out RelatedUID);
            if (MediaRoomUID > 0)
            {
                if (RelatedUID > 0)
                {
                    relatedENT.MediaRoomRelatedUID = RelatedUID;
                    relatedENT.Deleted = 0;
                    relatedENT = relatedBLL.GetEntity(relatedENT);
                    if (relatedENT != null)
                    {
                        relatedENT.MediaRoomUID = MediaRoomUID;
                        relatedBLL.UpdateENT(relatedENT);
                    }
                }
                else
                {
                    relatedENT.MediaRoomUID = MediaRoomUID;
                    relatedENT.Category = Constant.MediaRoomCategory.contactperson_photo;
                    relatedENT.Deleted = 0;
                    relatedENT.IsPublish = 1;
                    relatedENT.RelatedUID = cpuid;
                    relatedBLL.InsertENT(relatedENT);
                }
            }
            else
            {
                if (RelatedUID > 0)
                {
                    relatedENT.MediaRoomRelatedUID = RelatedUID;
                    relatedENT.Deleted = 1;
                    relatedBLL.UpdateENT(relatedENT);
                }
            }
        }

        protected void ddlArea_SelectedIndexChanged(object sender, EventArgs e)
        {
            BindCountry();
        }

        protected void ddlActivityType_SelectedIndexChanged(object sender, EventArgs e)
        {
            BindActivityName();
        }

        protected void rptCommitteeMember_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Literal ltYear = e.Item.FindControl("ltYear") as Literal;
                Literal ltDate = e.Item.FindControl("ltDate") as Literal;
                Literal ltType = e.Item.FindControl("ltType") as Literal;
                Literal ltPosition = e.Item.FindControl("ltPosition") as Literal;
                tblCPerson_CommMember comm = e.Item.DataItem as tblCPerson_CommMember;
                if (comm != null)
                {
                    ltYear.Text = comm.Year;
                    ltDate.Text = DateFormat(comm.StartDate) + " to " + DateFormat(comm.EndDate);
                    ltType.Text = comm.mtblCommType.CommType_Eng;
                    ltPosition.Text = comm.mtblCommPosition.CommPosition_Eng;
                }
            }
        }
        #endregion

        #region nicky Log
        static tblContactPerson staticCPerson;
        static tblContactInfo staticContactInfo;
        static tblAddress staticAddress;
        static string ActivityTypeUID =string.Empty;
        static List<tblCPerson_CommMember> listCPersonCommMembe;
        static int MedioVal;

        /// <summary>
        /// 将初始化的数据写入静态变量
        /// </summary>
        protected void BindStaticInfo()
        {
            ActivityTypeUID = string.Empty;
            staticCPerson = new tblContactPerson();
            staticContactInfo = new tblContactInfo();
            staticAddress = new tblAddress();
            staticCPerson = GetCPValue(staticCPerson);
            staticContactInfo = GetInfoValue(staticContactInfo);
            staticAddress = GetAddressValue(staticAddress);
            ActivityTypeUID = ddlActivityType.SelectedValue;
            listCPersonCommMembe = BindCPerson_CommMember();
            MedioVal = hidMediaRoomUID.Value.Equals("") ? 0 : Convert.ToInt32(hidMediaRoomUID.Value);
        }
        /// <summary>
        /// 绑定静态变量listCPersonCommMembe
        /// </summary>
        /// <returns></returns>
        protected List<tblCPerson_CommMember> BindCPerson_CommMember()
        {
            List<tblCPerson_CommMember> list = new List<tblCPerson_CommMember>();
            listCPersonCommMembe = new List<tblCPerson_CommMember>();
            tblCust_ContactPerson cust_CPENT = new tblCust_ContactPerson();
            tblCust_ContactPersonBLL cust_CPBLL = new tblCust_ContactPersonBLL();
            cust_CPENT.CustomerUID = customeruid;
            if (cpuid > 0)
                cust_CPENT.ContactPersonUID = cpuid;
            cust_CPENT.Deleted = 0;
            tblCPerson_CommMemberBLL cp_commBLL = new tblCPerson_CommMemberBLL();
            list = cp_commBLL.GetListByCust_CPerson(cust_CPENT, true).ToList();
            return list;
        }
        /// <summary>
        /// 返回ContactPerson改变的数据
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        protected string CPerson(string info)
        {
            if (ActivityTypeUID != ddlActivityType.SelectedValue) { info += " Activity Type change to" + ddlActivityType.DataTextField; }
            if (staticCPerson.ActivityUID != Convert.ToInt32(ddlActivityName.SelectedValue)) { info += " ActivityName change to" + ddlActivityName.DataTextField; }
            if (staticCPerson.SalutationUID != Convert.ToInt32(ddlSalutation.SelectedValue)) { info += " Salutation change to" + ddlSalutation.DataTextField; }
            if(Val(staticCPerson.ChristianName )!= txtChristianName.Text){info+=" ChristianName change to"+txtChristianName.Text;}
            if(Val(staticCPerson.FirstName_Eng )!= txtFirstName_Eng.Text){info+=" First Name change to"+txtFirstName_Eng.Text;}
            if(Val(staticCPerson.LastName_Eng )!= txtLastName_Eng.Text){info+=" Last Name change to"+txtLastName_Eng.Text;}
            if(Val(staticCPerson.OtherTitle_Eng )!= txtOtherTitle_Eng.Text){info+=" Other Title change to"+txtOtherTitle_Eng.Text;}
            if(Val(staticCPerson.FirstName_Chi )!= txtFirstName_Chi.Text){info+="姓 change to"+txtFirstName_Chi.Text;}
            if(Val(staticCPerson.LastName_Chi )!= txtLastName_Chi.Text){info+="名 change to"+txtLastName_Chi.Text;}
            if(Val(staticCPerson.OtherTitle_Chi )!= txtOtherTitle_Chi.Text){info+="	名銜  change to"+txtOtherTitle_Chi.Text;}
            if(Val(staticCPerson.Relationship )!= txtRelationship.Text){info+=" Relationship change to"+txtRelationship.Text;}
            if(Val(staticCPerson.Remark )!= txtRemark.Text){info+=" Remark change to"+txtRemark.Text;}
            if (staticCPerson.RelatedContactPersonUID != Convert.ToInt32(ddlRelatedCP.SelectedValue)) { info += " Related Contact Person change to" + ddlRelatedCP.DataTextField; }
            if(Val(staticCPerson.HKID_PassportID )!= hidTxtHKID.Value){info+=" HKID change to"+hidTxtHKID.Value;}
            return info;
        }
        /// <summary>
        /// 返回JobNature更改的信息
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        protected string JobNatureInfo(string info)
        {
            List<int> addJob = new List<int>();
            List<int> delJob = new List<int>();

            mtblJobNature entJob = new mtblJobNature();
            List<mtblJobNature> A_JobList = mtblJobNatureBLL.GetInstance().GetListByENT(entJob);

            addJob = GetList(hidAddToJob);
            delJob = GetList(hidDelToJob);            
            if (addJob.Count() > 0)
            {
                info += "JobNature Add ";
                for (int i = 0; i < addJob.Count - 1; i++)
                {
                    var result = A_JobList.Where(a => a.JobNatureUID == Convert.ToInt32(addJob[i])).Select(p => p).ToList();
                    foreach (mtblJobNature item in result)
                    {
                        info += item.JobNature_Eng + ",";
                    }
                }
            }
            if (delJob.Count() > 0)
            {
                info += "JobNature delete ";
                for (int i = 0; i < delJob.Count - 1; i++)
                {
                    var result = A_JobList.Where(a => a.JobNatureUID == Convert.ToInt32(delJob[i])).Select(p => p).ToList();
                    foreach (mtblJobNature item in result)
                    {
                        info += item.JobNature_Eng + ",";
                    }
                }
            }
            return info;
        }
        /// <summary>
        /// 返回Job Attrbute更改的信息
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        protected string JobAttributeInfo(string info)
        {
            List<int> addAttr = new List<int>();
            List<int> delAttr = new List<int>();

            mtblAttribute entAttr = new mtblAttribute();
            List<mtblAttribute> A_AttrList = mtblAttributeBLL.GetInstance().GetListByENT(entAttr);

            addAttr = GetList(hidAddToAttribute);
            delAttr = GetList(hidDelToAttribute);
            if (addAttr.Count() > 0)
            {
                info += "Attribute Add ";
                for (int i = 0; i < addAttr.Count - 1; i++)
                {
                    var result = A_AttrList.Where(a => a.AttributeUID == Convert.ToInt32(addAttr[i])).Select(p => p).ToList();
                    foreach (mtblAttribute item in result)
                    {
                        info += item.Attribute_Eng + ",";
                    }
                }
            }
            if (delAttr.Count() > 0)
            {
                info += "Attribute delete ";
                for (int i = 0; i < delAttr.Count - 1; i++)
                {
                    var result = A_AttrList.Where(a => a.AttributeUID == Convert.ToInt32(delAttr[i])).Select(p => p).ToList();
                    foreach (mtblAttribute item in result)
                    {
                        info += item.Attribute_Eng + ",";
                    }
                }
            }
            return info;
        }
        /// <summary>
        /// 返回地址被更改的信息
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        protected string AddressInfo(string info)
        {
            if (Val(staticAddress.Area_Chi) != txtArea_Chi.Text) { info += ", 地區 change to " + txtArea_Chi.Text; }
            if (Val(staticAddress.Area_Eng) != txtArea_Eng.Text) { info += " , Area change to " + txtArea_Eng.Text; }
            if (Val(staticAddress.City_Chi) != txtCity_Chi.Text) { info += " , 城市 change to " + txtCity_Chi.Text; }
            if (Val(staticAddress.City_Eng) != txtCity_Eng.Text) { info += " , City change to " + txtCity_Eng.Text; }
            if (Val(staticAddress.District_Chi) != txtDistrict_Chi.Text) { info += " , 區域 change to " + txtDistrict_Chi.Text; }
            if (Val(staticAddress.District_Eng) != txtDistrict_Eng.Text) { info += " , District change to " + txtDistrict_Eng.Text; }
            if (Val(staticAddress.Flat_Bldg_Eng) != txtFlat_Eng.Text) { info += " , 室, 樓層, 大廈 change to " + txtFlat_Eng.Text; }
            if (Val(staticAddress.Flat_Bldg_Chi) != txtFlat_Chi.Text) { info += " , Flat_Bldg change to " + txtFlat_Chi.Text; }
            if (Val(staticAddress.Province_Chi) != txtProvince_Chi.Text) { info += " , 州, 省 change to " + txtProvince_Chi.Text; }
            if (Val(staticAddress.Province_Eng) != txtProvince_Eng.Text) { info += " , Province change to " + txtProvince_Eng.Text; }
            if (Val(staticAddress.Street_Rd_Chi) != txtStreet_Chi.Text) { info += " , 街道 change to " + txtStreet_Chi.Text; }
            if (Val(staticAddress.Street_Rd_Eng) != txtStreet_Eng.Text) { info += " , Street_Rd change to" + txtStreet_Eng.Text; }
            if (Val(staticAddress.PostalCode) != txtPostCode.Text) { info += " , PostalCode change to " + txtPostCode.Text; }
            if (Val(staticAddress.Department_Eng) != ddlArea.SelectedItem.Text) { info += " , Continent change to " + ddlArea.SelectedItem.Text; }
            if (Val(staticAddress.Department_Chi) != ddlCountry.SelectedItem.Text) { info += " , Country change to" + ddlCountry.SelectedItem.Text; }
            return info;
        }
        /// <summary>
        /// 返回contactInfo被更改的信息
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        protected string contactInfo(string info)
        {
            if (staticContactInfo != null)
            {
                tblContactInfo infoENT = new tblContactInfo();
                infoENT = GetInfoValue(infoENT);

                if (Val(staticContactInfo.Tel1) != Val(infoENT.Tel1) | Val(staticContactInfo.Tel2) != Val(infoENT.Tel2) | Val(staticContactInfo.Tel3) != Val(infoENT.Tel3) | Val(staticContactInfo.Tel4) != Val(infoENT.Tel4) | Val(staticContactInfo.Tel5) != Val(infoENT.Tel5))
                {
                    info += "Tel have change; ";
                }
                if (staticContactInfo.Tel1_IsDNC != infoENT.Tel1_IsDNC | staticContactInfo.Tel2_IsDNC != infoENT.Tel2_IsDNC | staticContactInfo.Tel3_IsDNC != infoENT.Tel3_IsDNC | staticContactInfo.Tel4_IsDNC != infoENT.Tel4_IsDNC | staticContactInfo.Tel5_IsDNC != infoENT.Tel5_IsDNC)
                {
                    info += "Tel DNC have change; ";
                }
                if (staticContactInfo.Tel1_IsSubscribe != infoENT.Tel1_IsSubscribe | staticContactInfo.Tel2_IsSubscribe != infoENT.Tel2_IsSubscribe | staticContactInfo.Tel3_IsSubscribe != infoENT.Tel3_IsSubscribe | staticContactInfo.Tel4_IsSubscribe != infoENT.Tel4_IsSubscribe | staticContactInfo.Tel5_IsSubscribe != infoENT.Tel5_IsSubscribe)
                {
                    info += "Tel Subscrib have change; ";
                }
                if (Val(staticContactInfo.Fax1) != Val(infoENT.Fax1) | Val(staticContactInfo.Fax2) != Val(infoENT.Fax2) | Val(staticContactInfo.Fax3) != Val(infoENT.Fax3) | Val(staticContactInfo.Fax4) != Val(infoENT.Fax4) | Val(staticContactInfo.Fax5) != Val(infoENT.Fax5))
                {
                    info += "Fax have change";
                }
                if (staticContactInfo.Fax1_IsDNC != infoENT.Fax1_IsDNC | staticContactInfo.Fax2_IsDNC != infoENT.Fax2_IsDNC | staticContactInfo.Fax3_IsDNC != infoENT.Fax3_IsDNC | staticContactInfo.Fax4_IsDNC != infoENT.Fax4_IsDNC | staticContactInfo.Fax5_IsDNC != infoENT.Fax5_IsDNC)
                {
                    info += "Fax DNC chave change";
                }
                if (staticContactInfo.Fax1_IsSubscribe != infoENT.Fax1_IsSubscribe | staticContactInfo.Fax2_IsSubscribe != infoENT.Fax2_IsSubscribe | staticContactInfo.Fax3_IsSubscribe != infoENT.Fax3_IsSubscribe | staticContactInfo.Fax4_IsSubscribe != infoENT.Fax4_IsSubscribe | staticContactInfo.Fax5_IsSubscribe != infoENT.Fax5_IsSubscribe)
                {
                    info += "Fax Subscribe have change";
                }
                if (Val(staticContactInfo.Email1) != Val(infoENT.Email1) | Val(staticContactInfo.Email2) != Val(infoENT.Email2) | Val(staticContactInfo.Email3) != Val(infoENT.Email3) | Val(staticContactInfo.Email4) != Val(infoENT.Email4) | Val(staticContactInfo.Email5) != Val(infoENT.Email5))
                {
                    info += "Email have change";
                }
                if (staticContactInfo.Email1_IsSubscribe != infoENT.Email1_IsSubscribe | staticContactInfo.Email2_IsSubscribe != infoENT.Email2_IsSubscribe | staticContactInfo.Email3_IsSubscribe != infoENT.Email3_IsSubscribe | staticContactInfo.Email4_IsSubscribe != infoENT.Email4_IsSubscribe | staticContactInfo.Email5_IsSubscribe != infoENT.Email5_IsSubscribe)
                {
                    info += "Email Subscribe have change";
                }
                if (staticContactInfo.Email1_HardBounce != infoENT.Email1_HardBounce | staticContactInfo.Email2_HardBounce != infoENT.Email2_HardBounce | staticContactInfo.Email3_HardBounce != infoENT.Email3_HardBounce | staticContactInfo.Email4_HardBounce != infoENT.Email4_HardBounce | staticContactInfo.Email5_HardBounce != infoENT.Email5_HardBounce)
                {
                    info += "Email Subscribe have change";
                }
                if (staticContactInfo.Website1 != infoENT.Website1 | staticContactInfo.Website2 != infoENT.Website2 | staticContactInfo.Website3 != infoENT.Website3 | staticContactInfo.Website4 != infoENT.Website4 | staticContactInfo.Website5 != infoENT.Website5)
                {
                    info += "Website have change";
                }
                if (staticContactInfo.Website1_Type != infoENT.Website1_Type | staticContactInfo.Website2_Type != infoENT.Website2_Type)
                {
                    info += "Website type have change";
                }
            }
            return info;
        }
        /// <summary>
        /// 返回CPersonCommMembe被更改的信息
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        protected string CPersonCommMembe(string info)
        {
            int.TryParse(Request.QueryString[Constant.UrlParamName.ContactPersonUID], out cpuid);
            List<tblCPerson_CommMember> list = new List<tblCPerson_CommMember>();
            list=BindCPerson_CommMember();
            if (listCPersonCommMembe.Count() != list.Count()) {
                for (int i = 0; i < listCPersonCommMembe.Count(); i++) {
                    var m = list.Select(a => a.Cperson_CommMemberUID).Contains(listCPersonCommMembe[i].Cperson_CommMemberUID);
                    if (m==false ) {
                        info += "Year / Term:" + listCPersonCommMembe[i].Year + ",Date:" + listCPersonCommMembe[i].StartDate + " to " + listCPersonCommMembe[i].EndDate + "  Committee Type:" + listCommType.Where(a => a.CommTypeUID == listCPersonCommMembe[i].CommTypeUID).First().CommType_Eng + ",Committee Position:" +listCommPosition.Where(a=>a.CommPositionUID==listCPersonCommMembe[i].CommPositionUID).First().CommPosition_Eng + "have been delete";
                    }
                }
            
                for (int i = 0; i <list.Count(); i++)
                {
                    var m = listCPersonCommMembe.Select(a => a.Cperson_CommMemberUID).Contains(list[i].Cperson_CommMemberUID);
                    if (m == false)
                    {
                        info += " a information with Year / Term:" + listCPersonCommMembe[i].Year + ",Date:" + listCPersonCommMembe[i].StartDate + " to " + listCPersonCommMembe[i].EndDate + "  Committee Type:" + listCommType.Where(a => a.CommTypeUID == listCPersonCommMembe[i].CommTypeUID).First().CommType_Eng + ",Committee Position:" + listCommPosition.Where(a => a.CommPositionUID == listCPersonCommMembe[i].CommPositionUID).First().CommPosition_Eng+" have add";
                    }
                }
            }
            return info;
        }
        protected string UploadMide(string info) {
            int Media = hidMediaRoomUID.Value.Equals("") ? 0 : Convert.ToInt32(hidMediaRoomUID.Value);
            if (MedioVal != Media) {
                info = "ContactPerson Image have change";
            }
            return info;
        }
        protected void WriteToLog()
        {           
            string ChangeInfo=string.Empty;
            if (txtChristianName.Text.Trim() != "")
            {
                ChangeInfo += CPerson(ChangeInfo);
                ChangeInfo += UploadMide(ChangeInfo);
                ChangeInfo += AddressInfo(ChangeInfo);
                ChangeInfo = contactInfo(ChangeInfo);
                ChangeInfo = ChangeInfo.Replace("change to", "add:");
                InsertToHistory(15, "", ChangeInfo);                
                ChangeInfo = string.Empty;
                ChangeInfo += JobNatureInfo(ChangeInfo);
                InsertToHistory(16, "Job Job Nature", ChangeInfo);
                ChangeInfo = string.Empty;
                ChangeInfo += JobAttributeInfo(ChangeInfo);
                InsertToHistory(19, "Job Attribute", ChangeInfo);
                ChangeInfo = string.Empty;
                ChangeInfo += CPersonCommMembe(ChangeInfo);
                InsertToHistory(12, "Committee Member", ChangeInfo);
            }
            else {
                ChangeInfo += CPerson(ChangeInfo);
                ChangeInfo += UploadMide(ChangeInfo);
                ChangeInfo += AddressInfo(ChangeInfo);
                ChangeInfo = contactInfo(ChangeInfo);
                InsertToHistory(22, "", ChangeInfo);
                ChangeInfo = string.Empty;
                ChangeInfo += JobNatureInfo(ChangeInfo);
                InsertToHistory(17, "Job Job Nature", ChangeInfo);
                ChangeInfo = string.Empty;
                ChangeInfo += JobAttributeInfo(ChangeInfo);
                InsertToHistory(20, "Job Attribute", ChangeInfo);
                ChangeInfo = string.Empty;
                ChangeInfo += CPersonCommMembe(ChangeInfo);
                InsertToHistory(13, "Committee Member", ChangeInfo);
            }
        }
        protected int InsertToHistory(int historytypeUID, string info_prat, string ChangeInfo)
        {
            int tal = 0;
            if (ChangeInfo.Trim().Length > 5)
            {
                BasePage basepage = new BasePage();
                string LoginName = basepage.GetManageFromSession().User_Name;
                Literal CompanyName = usermeg.FindControl("ltlCompanyName_eng") as Literal;
                tblHistory entlog = new tblHistory();
                entlog.HistoryCatUID = 2;
                entlog.HistoryTypeUID = historytypeUID;
                entlog.CustomerUID = Convert.ToInt32(Request.QueryString[Constant.UrlParamName.CustomerUID]);
                entlog.Cust_MemberUID = 0;
                entlog.ContactPersonUID = 0;
                entlog.History_Detail = LoginName + " {" + CompanyName.Text + "}{ContactPerson" + info_prat + "} " + ChangeInfo;
                entlog.LastModifyBy = LoginName;
                tal = tblHistoryBLL.GetInstance().InsertENT(entlog);
            }
            return tal;
        }
        protected string Val(string str)
        {
            if (string.IsNullOrEmpty(str))
                str = "";
            return str;
        }
        #endregion



    }
}